﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using DHQGHN.DAL.DAO;
using DHQGHN.DAL.DAO.MappingDB;
using DHQGHN.DAL.DataMapper;
using DHQGHN.DAL.Models;
using DHQGHN.DAL.Models.MappingDB;

namespace DHQGHN.DAL.BO.MappingDB
{
    public class SD_ConfigSourceBO : BaseBO
    {
        #region Field Name in return DataSet
        //Field Name in return DataSet
       public const string Field_ConfigSourceID = "ConfigSourceID";
        public const string Field_DataSource = "DataSource";
        public const string Field_ServerName = "ServerName";
        public const string Field_sUser = "sUser";
        public const string Field_sPassWord = "sPassWord";
        public const string Field_DataBaseName = "DataBaseName";  

        public const string Field_DS_IsActive = "IsActive";
        #endregion


        public String _connectionString;
        private SD_ConfigSourceDAO _shareDAO;
        public SD_ConfigSourceBO(string connString)
        {
            this._connectionString = connString;

        }
        public SD_ConfigSourceBO()
        {
            this._connectionString = DEFAULT_CONN_STRING;

        }

        public SD_ConfigSourceDAO CreateSQLDAO()
        {
            return new SD_ConfigSourceDAO(_connectionString, DEFAULT_MAPPER_TYPE);
        }

        public SD_ConfigSource Save(SD_ConfigSource model)
        {
            try
            {
                _shareDAO = CreateSQLDAO();
                return _shareDAO.Save(model);
            }
            catch(Exception )
            {
                throw ;
            }
        }

        public SD_ConfigSource GetLatestConfigSource()
        {
            try
            {
                _shareDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {SD_ConfigSource.Field_ConfigSourceID,Field_ConfigSourceID},
                    {SD_ConfigSource.Field_DataBaseName,Field_DataBaseName},
                    {SD_ConfigSource.Field_DataSource,Field_DataSource},                    
                    {SD_ConfigSource.Field_ServerName,Field_ServerName},
                    {SD_ConfigSource.Field_sPassWord,Field_sPassWord},
                    {SD_ConfigSource.Field_sUser,Field_sUser},
                   
                    
                };
                return _shareDAO.GetSdConfigSource(mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }
       

        public List<SD_MappingTable> GetAllTableName(int sourceId){
              try
            {
                _shareDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {SD_MappingTable.Field_ConfigSourceID,SD_MappingTable.Field_ConfigSourceID},
                    {SD_MappingTable.Field_SourceTable,SD_MappingTable.Field_SourceTable},
                                   
                    
                };
                return _shareDAO.GetAllTableName(sourceId,mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

    }
}
